<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://www.zkingsoft.com" prefix="matrix"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/plugin/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
	<!-- 搜索框部分start -->
<matrix:btn value="user:search">
	<div class="row" >
		<div class="col-sm-12" >
			<form class="form-inline" id="serchform">
				
					<div class="btn-group search-list " data-for="search-text">
						  
					       <div class="form-group mr-20">
								<label>活动名称：</label>
								<input id="search-text" name="hacName" placeholder="输入活动名称"
									type="text" class="form-control">
							</div> 
							 <input type="hidden" name="sort" value="create_time"> 
						    <input type="hidden" name="order" value="DESC">  
					</div>
					
					<div class="form-group mr-20">
						<button  onclick="myGrid.serchData()" type="button" class="btn btn-info"><i class="fa fa-search " ></i> 搜索</button>
						<button  type="reset" class="btn btn-info "><i class="fa fa-refresh " ></i> 重置</button>
					</div>
				
			</form>
		</div>
	</div>
</matrix:btn>
	<!-- 搜索框部分en -->
<div class="ibox-content radius-5 mt-5 mpanel">
		
	<div class="row" >
		<div class="col-sm-12" >
			<!-- 功能按钮部分 -->
					<div class="option-bar">
						<matrix:btn value="helpActivity:add">
							<button onclick="openAdd()" type="button"
								class="btn btn-success btn-sm">
								<i class="fa fa-plus"></i> 新增
							</button>
						</matrix:btn>
					</div>
			<table id="mgrid" >
				<thead>
					<tr>
						<!-- <th data-checkbox="true"  ></th> -->
						<th data-formatter="MGrid.indexfn" data-align="center"  data-width="30px" >序号</th>
						<th data-field="createTime" data-formatter="MGrid.getTime"  >创建时间</th>
						<th data-field="hacName" data-sortable="true">活动名称</th>
						<th data-field="hacPosterImg" data-formatter="MGrid.getImage">海报图片</th>
						<!-- <th data-field="hacIntroduce"  data-formatter="formatStr">介绍</th> -->
						<!-- <th data-field="hacUseTime" data-formatter="MGrid.getTime" >使用失效时间</th> -->
						<th data-field="hacNum" >需要助力人数</th>
						<!-- <th data-field="sharePrizeName" >分享奖品名称</th>
						<th data-field="helpPrizeName" >助力奖品名称</th> -->
						<!-- <th data-field="hacQrcode" data-formatter="MGrid.getImage" >二维码</th> -->
						<th data-field="hacStatus" data-formatter="formatStatus">状态</th>
						<th data-align="center"  data-width="150px" data-field="actId" data-formatter="buidOperate">操作</th> 
					</tr>
				</thead>
			</table>
	</div>
	</div>
</div>
</div>
<script type="text/javascript"
src="${path }/resource/js/systools/MJsBase.js"></script>
<script type="text/javascript">
	
	var myGrid;
	
		$(function(){
			var delPath="";
			<matrix:btn value="helpActivity:del">
			delPath="${path}/do/admin/bizHelpActivity/del";
			</matrix:btn>
			 myGrid=MGrid.initGrid({
				 url:"${path}/do/admin/bizHelpActivity/showList",
				 onLoadSuccess:function(data){
						console.log("onLoadSuccess:")
					},
				 delUrl:delPath
			 });
			 
		});
		function formatStatus(val, row, index){
			var str="";
			//1:保存 2：发布 3：下架 4：删除
			if(val=='1'){//text-primary
				return "<sapn  class='text-muted'>已保存</span><br>"+str
			}else if(val=='2'){
				return "<sapn class='text-success'>已发布</span><br>"+str
			}else if(val=='3'){
				return "<sapn class='text-danger'>已下架</sapn><br>"+str
			}
			return ""
		}
		
		
	
		function buidOperate(value, row, index){
			var html=[];
			<matrix:btn value="helpActivity:edit">
			html[0] = '<a onClick="openEdit(\'' + value
					+ '\')"  title="编辑" class="fa fa-edit option"></a>'
					if(row.hacStatus=='1' || row.hacStatus=='3'){
						html[1] = '<a onClick="up(\'' + value
						+ '\')"  title="发布" class="fa fa-arrow-up option"></a>'
					}else if(row.hacStatus=='2'){
						html[2] = '<a onClick="down(\'' + value
						+ '\')"  title="下架" class="fa fa-arrow-down option"></a>'
					}
			</matrix:btn>

			<matrix:btn value="helpActivity:del">
			html[3] = '<a onClick="myGrid.delItem(\''
					+ value
					+ '\')" title="删除" class="fa fa-close option text-danger"></a>';
			</matrix:btn>
			return html.join(""); 
		}
		
		<matrix:btn value="helpActivity:add">
		//打开添加界面
		function openAdd() {
			layer.full(layer.open({
				type : 2,
				title : "添加活动",
				maxmin : true,
				area : [ MUI.SIZE_L, '500px' ],
				content : [ '${path}/do/admin/bizHelpActivity/editForm' ]
			}));
		}
		</matrix:btn>
		<matrix:btn value="helpActivity:edit">
		//打开编辑界面
		function openEdit(id) {
			layer.full(	layer.open({
				type : 2,
				title : "编辑活动",
				area : [ MUI.SIZE_L, '500px' ],
				maxmin : true,
				content : [ '${path}/do/admin/bizHelpActivity/editForm?id=' + id ]
			}));
		}
		</matrix:btn>
		
		function formatStr(val){
			var s=val;
			if(val){
				if(val.length>10){
					  s=val.substring(0,10)+"...";
					  return "<abbr title='"+val+"'>"+s+"</abbr>";
				}
				
			}
			return val;
		}
		
		function up(val){
			upOrdown(val,2);
		}
		
		function down(val){
			upOrdown(val,3);
		}
		
		function upOrdown(val,status){
			$.AjaxProxy(
					{
						p : {actId:val,hacStatus:status}

					}).invoke(
					"${path}/do/admin/bizHelpActivity/upOrdown",
					function(loj) {
						layer.msg(loj.getValue("info"))
						myGrid.serchData();
					})
		}
	</script>
</body>
</html>
